package com.hptpd.questionnairesurvey.service.impl;

import com.hptpd.questionnairesurvey.component.Result;
import com.hptpd.questionnairesurvey.domain.Department;
import com.hptpd.questionnairesurvey.repository.DepartmentRep;
import com.hptpd.questionnairesurvey.repository.UserRep;
import com.hptpd.questionnairesurvey.service.IDepartmentService;
import com.hptpd.questionnairesurvey.service.base.BaseServiceImpl;
import com.hptpd.questionnairesurvey.utils.DepartmentRecursion;
import com.hptpd.questionnairesurvey.vo.DepartmentVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * \* Created with IntelliJ IDEA.
 * \* Date: 2019/9/10
 * \*
 * \* Description:
 * \
 *
 * @author walter_long
 */
@Service("iDepartmentService")
public class DepartmentServiceImpl extends BaseServiceImpl implements IDepartmentService {
    private Logger logger = LoggerFactory.getLogger(DepartmentServiceImpl.class);

    @Resource(name="departmentRep")
    private DepartmentRep departmentRep;

    @Resource(name="userRep")
    private UserRep userRep;

    @Override
    public Result listUserUnderDepartment(@NotNull Department parentDepartment) {

        return Result.fail(Result.ERROR_CODE, "后台未完成");
    }

    @Override
    public Result listDepartmentUnderParentDepartment(@NotNull Department parentDepartment) {
        Department department = departmentRep.findByIdIs(parentDepartment.getId());
        if (null == department) {
            return Result.badArgumentValue();
        }
        DepartmentRecursion departmentRecursion = new DepartmentRecursion(department);
        List<DepartmentVo> departmentVos = departmentRecursion.getDepartmentVos();
        return Result.ok(departmentVos);
    }
}
